package com.video.tiktokdownloader.nowatermark

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.bumptech.glide.Glide
import com.video.tiktokdownloader.nowatermark.bean.MediaEntity
import kotlinx.android.synthetic.main.activity_video_show.*
import java.io.File

class VideoShowActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_video_show)


        val data = intent.getSerializableExtra("media")
        if (data is MediaEntity) {
            try {
                var filePath:String? = null
                if (data.what == 0) {
                    filePath = File(getVideoDir(), data.fileName).absolutePath
                } else if (data.what == 1) {
                    iv_detail.visibility = View.VISIBLE
                    Glide.with(this).load(data.cover).centerInside().into(iv_detail)
                    filePath = File(getMusicDir(), data.fileName).absolutePath
                }
                vv_detail.setVideoPath(filePath)
                vv_detail.setOnPreparedListener {
                    //                                it.setVolume(0F, 0F)
                    it.isLooping = true
                    vv_detail.start()
                }
            } catch (e: Exception) {
            }
        } else {
            finish()
            return
        }

        video_close.setOnClickListener {
            finish()
        }
    }
}
